package com.chromatic.competition.view.recruitment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.chromatic.competition.R;
import com.chromatic.competition.model.UserInformation;
import com.chromatic.competition.utils.UserManager;

public class TeammateDetailActivity extends AppCompatActivity {
    private TextView nicknameTextView;
    private TextView realnameTextView;
    private TextView studentIdTextView;
    private TextView genderTextView;
    private TextView provinceTextView;
    private TextView cityTextView;
    private TextView universityTextView;
    private TextView collegeTextView;
    private TextView gradeTextView;
    private TextView majorTextView;
    private TextView locationTextView;
    private TextView resumeTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_teammate_detail);

        // 初始化视图
        nicknameTextView = findViewById(R.id.nicknameTextView);
        realnameTextView = findViewById(R.id.realnameTextView);
        studentIdTextView = findViewById(R.id.studentIdTextView);
        genderTextView = findViewById(R.id.genderTextView);
        provinceTextView = findViewById(R.id.provinceTextView);
        cityTextView = findViewById(R.id.cityTextView);
        universityTextView = findViewById(R.id.universityTextView);
        collegeTextView = findViewById(R.id.collegeTextView);
        gradeTextView = findViewById(R.id.gradeTextView);
        majorTextView = findViewById(R.id.majorTextView);
        locationTextView = findViewById(R.id.locationTextView);
        resumeTextView = findViewById(R.id.resumeTextView);

        // 从Intent中获取队友ID
        int teammateId = getIntent().getIntExtra("teammate_id", 0);
        Log.d("TeammateDetailActivity","队友的ID是：" + teammateId);

        // 获取队友信息
        getTeammateInformation(teammateId);

        ImageView backButton = findViewById(R.id.backButton);
        backButton.setOnClickListener(v -> {
            onBackPressed(); // 调用系统返回操作
        });
    }

    private void getTeammateInformation(int userId) {
        // 调用您的获取用户信息的方法，并传递回调处理结果
        UserManager.getUserInformation(userId, new UserManager.UserInformationCallback() {
            @Override
            public void onSuccess(UserInformation userInformation) {
                // 显示队友信息
                showTeammateInformation(userInformation);
            }
            @Override
            public void onError(String errorMessage) {
                // 处理错误情况
                Toast.makeText(TeammateDetailActivity.this, "错误: " + errorMessage, Toast.LENGTH_SHORT).show();
            }
        });
    }

    @SuppressLint("SetTextI18n")
    private void showTeammateInformation(UserInformation userInformation) {
        // 显示队友详情信息
        nicknameTextView.setText(userInformation.getNickname());
        realnameTextView.setText("真实姓名：" + userInformation.getRealname());
        studentIdTextView.setText("学号：" + userInformation.getStudentId());
        genderTextView.setText("性别：" + userInformation.getGender());
        provinceTextView.setText("省份：" + userInformation.getProvince());
        cityTextView.setText("城市：" + userInformation.getCity());
        universityTextView.setText("学校：" + userInformation.getUniversity());
        collegeTextView.setText("学院：" + userInformation.getCollege());
        gradeTextView.setText("年级：" + userInformation.getGrade());
        majorTextView.setText("专业：" + userInformation.getMajor());
        locationTextView.setText("地址：" + userInformation.getLocation());
        resumeTextView.setText(userInformation.getResume());
    }
}